#include "FoodBox.h"


FoodBox::FoodBox(void)
{
}

FoodBox::FoodBox(float x, float y, int deltaTime,int resourceName,CResourceManager *rm):MObject(x,y,0,0,deltaTime,resourceName,rm)
{
	_objectType = CResourceManager::TYPE_BOXWITHMUSHROOM;
	_spriteNormal = rm->getSprite(CResourceManager::QUESTIONBOX);
	_spriteEmpty = rm->getSprite(CResourceManager::EMPTYBOX);
	_spriteCoin = rm->getSprite(CResourceManager::COIN);
	_status = STATUS_NORMAL;

	_scored = 100;
	_isAnimating = true;
}
	//setStatus(STATUS_NORMAL);


	//_spriteCoin = rm->getSprite(CResourceManager::C
	

void FoodBox::Render()
{
	MObject::Render();
	if (_objectType == CResourceManager::TYPE_BOXWITHCOIN && _isAnimating)
	{
		Vector v = CScreen::getPosition();
		_spriteCoin->Render(_tp.getX() - v.getX(),_tp.getY() - v.getY());
	}
}

void FoodBox::actAfterCollided(int Direction, shared_ptr<MObject> Object)
{
	/*if (Object->getObjectType()/10 == CResourceManager::TYPE_MARIO && Object->getPosition().getY() >= (_y + 32))
			setStatus(STATUS_EMPTY);*/
}

void FoodBox::setStatus(int Status)
{
	_status = Status;
	switch(Status)
	{
	case STATUS_NORMAL:
		{
			_sprite = _spriteNormal;
			break;
		}
	case STATUS_EMPTY:
		{
			_sprite = _spriteEmpty;
			if (_objectType == CResourceManager::TYPE_BOXWITHCOIN)
			{
				_tv = Vector(0,-1.f);
				_tp = Vector(_x, _y - 32);
				CMarioSound::getInstance()->Play(CMarioSound::SOUND_GETCOIN,false);

			}
			
			break;
		}

	
	}
}

void FoodBox::Animate()
{
	if (_objectType == CResourceManager::TYPE_BOXWITHCOIN)
	{
		_tp.setX(_tp.getX() + _tv.getX()*_deltaTime);
		_tp.setY(_tp.getY() + _tv.getY()*_deltaTime);

		_tv.setY(_tv.getY() + 0.1f);
		if (_tv.getY() >= 0)
			_isAnimating = false;
			
	}
}

FoodBox::~FoodBox(void)
{
}
